﻿Imports DTO
Imports System.Data.OleDb
Public Class LoaiSachDAO

    Public Function LayThongTinTheLoaiTheoMa(ByVal maTheLoai As Integer) As LoaiSachDTO
        Dim sql As String = "SELECT MaTheLoai,TenTheLoai FROM THELOAISACH WHERE MaTheLoai = " & maTheLoai.ToString()
        DataProvider.OpenConnecttion()
        Dim reader As OleDbDataReader = DataProvider.ExecSelect(sql)

        Dim ls As New LoaiSachDTO
        reader.Read()
        ls.MaTheLoai = reader.GetInt32(0)
        ls.TenTheLoai = reader.GetString(1)

        DataProvider.CloseConnect()
        Return ls
    End Function

    Public Function LayDSLoaiSach() As List(Of LoaiSachDTO)
        Dim sql As String = "Select MaTheLoai,TenTheLoai From THELOAISACH"
        DataProvider.OpenConnecttion()
        Dim reader As OleDbDataReader = DataProvider.ExecSelect(sql)
        Dim ds As New List(Of LoaiSachDTO)()
        While reader.Read
            Dim bc As New LoaiSachDTO()
            bc.MaTheLoai = reader.GetInt32(0)
            bc.TenTheLoai = reader.GetString(1)
            ds.Add(bc)
        End While
        DataProvider.CloseConnect()
        Return ds
    End Function

    Public Function ThemLoaiSach(ByVal sql As String) As Integer
        DataProvider.OpenConnecttion()
        Dim kq As Integer = DataProvider.ExecInsert(sql)
        DataProvider.CloseConnect()
        Return kq
    End Function

    Public Function CapNhatLoaiSach(ByVal sql As String) As Integer
        DataProvider.OpenConnecttion()
        Dim kq As Integer = DataProvider.ExecInsert(sql)
        DataProvider.CloseConnect()
        Return kq
    End Function
End Class
